package com.s.core.root;

import com.s.core.root.strategy.Strategy;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

@Slf4j
@AllArgsConstructor
public class CaseA {
    public String code;
    public String date;
    public Strategy.STRATEGY strategy;

    public boolean equals(Object object) {
        if (object instanceof CaseA) {
            return code.equals(((CaseA) object).code) && date.equals(((CaseA) object).date);
        }
        return false;
    }

    public static CaseA line2CaseA(String line) {
        if (!StringUtils.isEmpty(line) && !line.startsWith("#")) {
            if (line.split(",").length != 3) {
                log.error("line fmt error");
                return null;
            }
            String[] tmp = line.split(",");
            String code = tmp[0].trim();
            if (!Ad.me().getCodes().contains(code)) {
                log.error("code {} not exist", code);
                return null;
            }
            String date = tmp[1].trim();
            if (!Ad.me().getDateList().contains(date)) {
                log.error("date {} not exist", date);
                return null;
            }
            String strategy = tmp[2].trim();
            Strategy.STRATEGY s = Strategy.STRATEGY.byString(strategy);
            if (s == null) {
                log.error("strategy {} not exist", strategy);
                return null;
            }
            return new CaseA(code, date, s);
        }
        return null;
    }
}